import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/publicBussine/bussine_colors.dart';
import 'package:honeypotflutter/publicBussine/bussine_font.dart';
import 'package:honeypotflutter/publicBussine/bussine_image.dart';
import 'package:honeypotflutter/publicBussine/loginInfo/bussine_userInfo.dart';
import 'package:honeypotflutter/publicBussine/view/bussine_card.dart';
import 'package:honeypotflutter/publicBussine/view/bussine_switchMonry.dart';
import 'package:honeypotflutter/router/bussine_router_url.dart';

class DeliverSelectAccount extends StatelessWidget {
  DeliverSelectAccount({super.key});

  @override
  Widget build(BuildContext context) {
    return MGCard(
      margin: EdgeInsets.only(top: 16),
      padding: EdgeInsets.only(top: 20, left: 12, right: 12, bottom: 20),
      children: [
        Row(
          children: [
            Image.asset(
              MGImage.image("public_photo"),
              width: 80,
            ),
            SizedBox(
              width: 10,
            ),
            Column(
              children: [
                GetBuilder<UserInfoLogic>(
                    init: UserInfoLogic(),
                    builder: (controller) {
                      return Text(
                        controller.userInfo.phoneNumber ?? "",
                        style: TextStyle(
                          color: MGColors.text1Color,
                          fontWeight: FontWeight.bold,
                          fontSize: MGFont.titleFont3,
                        ),
                      );
                    }),
                SizedBox(height: 10),
                Text(
                  "欢迎回来~",
                  style: TextStyle(
                    color: MGColors.text3Color,
                    fontSize: MGFont.textFont1,
                  ),
                )
              ],
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
            )
          ],
        ),
        Container(
          margin: EdgeInsets.only(top: 20),
          padding: EdgeInsets.all(16),
          width: double.infinity,
          decoration: BoxDecoration(color: MGColors.backColor, borderRadius: BorderRadius.circular(8)),
          child: Row(
            children: [
              _accountWidget(),
              InkWell(
                child: Row(
                  children: [
                    Image.asset(
                      MGImage.image("deliver_exchange", type: ImagePathType.deliver),
                      width: 18,
                    ),
                    SizedBox(
                      width: 10,
                    ),
                    Text(
                      "切换支付方式",
                      style: TextStyle(
                        color: MGColors.text3Color,
                        fontSize: MGFont.textFont3,
                      ),
                    )
                  ],
                ),
                onTap: () {
                  Get.toNamed(MGRouterUrl.freePay_exchange);
                },
              )
            ],
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.start,
          ),
        )
      ],
    );
  }

  /*
  * 账户信息
  * */
  Widget _accountWidget() {
    return GetBuilder<UserInfoLogic>(
        init: UserInfoLogic(),
        builder: (controller) {
          bool isFreePay = (controller.userInfo.userFirstChoicePayType != null && controller.userInfo.userFirstChoicePayType! == 1);
          if (isFreePay) {
            return Text("支付宝免密支付", style: TextStyle(fontSize: MGFont.textFont1, color: MGColors.text1Color));
          } else {
            return Row(
              children: [
                MGSwitchMonry(
                  color: MGColors.text1Color,
                  monry: controller.userInfo.accountBalance,
                ),
                InkWell(
                  child: Container(
                    padding: EdgeInsets.only(left: 12, right: 12, top: 2, bottom: 2),
                    decoration: BoxDecoration(border: Border.all(color: MGColors.text3Color, width: 1), borderRadius: BorderRadius.circular(10)),
                    child: Text(
                      "充值",
                      style: TextStyle(color: MGColors.text1Color, fontSize: MGFont.textFont3),
                    ),
                  ),
                  onTap: () {
                    Get.toNamed(MGRouterUrl.recharge);
                  },
                )
              ],
              crossAxisAlignment: CrossAxisAlignment.end,
            );
          }
        });
  }
}
